import store from "../store";

export const getUserName = () => {
    let userName = store.getState().userName

    if (!userName) {
        let cacheUserName = localStorage.getItem('userName')

        if (cacheUserName) {
            store.dispatch({type: 'setUserName', data: cacheUserName})

            userName = cacheUserName
        }
    }

    return userName
}

export const setUserName = (userName) => {
    store.dispatch({type: "setUserName", data: userName})
    store.dispatch({type: "tipsPush", data: userName + ' 欢迎你...'})
}